/*
 * @lc app=leetcode.cn id=90 lang=cpp
 *
 * [90] 子集 II
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
    vector<vector<int>> ans;
    set<vector<int>> ans_s;
    void dfs(const vector<int>& nums, int start, vector<int>& res)
    {
        if(start == nums.size())
        {
            // ans.push_back(res);
            ans_s.insert(res);
            return;
        }
        res.push_back(nums[start]);
        dfs(nums, start + 1, res);
        res.erase(res.end() - 1);
        dfs(nums, start + 1, res);
    }
    vector<vector<int>> subsetsWithDup(vector<int>& nums) {
        vector<int> res;
        sort(nums.begin(), nums.end());//排序的目的是将重复的数字集中到一起，防止后续出现问题
        dfs(nums, 0, res);
        for(auto& v : ans_s)
        {
            ans.push_back(v);
        }
        return ans;
    }
};

// @lc code=end

